from langgraph.graph import START,END, StateGraph

#pip install -U langgraph
#pip install langchain


def my_node(state):
    return {"x":state["x"] + 1, "y":state["y"] + 1}

def my_node1(state):
    return {}
def my_node2(state):
    return {}
def my_node3(state):
    return {}
stat = StateGraph(dict)
stat.add_node(my_node)
stat.add_node(my_node1)
stat.add_node(my_node2)
stat.add_node(my_node3)
stat.add_edge(START, "my_node")
def router(state):
    return state.get("x") > 10
stat.add_edge("my_node", "my_node3")
stat.add_conditional_edges("my_node", router,{1:"my_node1",2:"my_node2"})
stat.add_edge("my_node1", END)
stat.add_edge("my_node2", END)
graph = stat.compile()
graph_png = graph.get_graph().draw_mermaid_png()
with open("graph.png", "wb") as f:
    f.write(graph_png)
#下载图片
print(graph)